package com.example.aigc_education.service.converter;

import com.example.aigc_education.domain.Theme;
import com.example.aigc_education.domain.request.AddThemeRequest;
import com.example.aigc_education.domain.vo.SubThemeVO;
import com.example.aigc_education.domain.vo.ThemeCompletionVO;
import com.example.aigc_education.domain.vo.ThemeV2VO;
import com.example.aigc_education.domain.vo.ThemeVO;
import com.example.aigc_education.enums.ThemeCompletionStatus;
import org.mapstruct.*;

import java.util.List;

@Mapper(componentModel = "spring")
public interface ThemeConverter {
    /**
     * AddThemeRequest-->Theme
     */
    Theme addThemeRequestToTheme(AddThemeRequest addThemeRequest);


    /**
     * Theme-->ThemeVO
     */
    @Mappings(
            value = {
                    @Mapping(target = "completionStatus", ignore = true)
            }
    )
    ThemeVO themeToThemeVO(Theme theme);

    //调用完自动转化后，会自动调用本方法
    @AfterMapping
    default void setCompletionStatus(Theme theme, @MappingTarget ThemeVO themeVO){
        Integer completionStatus = theme.getCompletionStatus();
        ThemeCompletionStatus themeCompletionStatus = ThemeCompletionStatus.fromValue(completionStatus);
        themeVO.setCompletionStatus(new ThemeVO.ThemeCompletionVO(themeCompletionStatus.getValue(), themeCompletionStatus.getTitle(), themeCompletionStatus.getColor()));
    }

    List<ThemeVO> themesToThemeVOs(List<Theme> themes);


    /**
     * Theme-->ThemeV2VO
     */
    @Mappings(
            value = {
                    @Mapping(target = "completionStatus", ignore = true)
            }
    )
    ThemeV2VO themeToThemeV2VO(Theme theme);

    //调用完自动转化后，会自动调用本方法
    @AfterMapping
    default void setCompletionStatus(Theme theme, @MappingTarget ThemeV2VO themeV2VO){
        Integer completionStatus = theme.getCompletionStatus();
        ThemeCompletionStatus themeCompletionStatus = ThemeCompletionStatus.fromValue(completionStatus);
        themeV2VO.setCompletionStatus(new ThemeCompletionVO(themeCompletionStatus.getTitle(), themeCompletionStatus.getColor()));
    }


    List<ThemeV2VO> themesToThemeV2VOs(List<Theme> themes);



    /**
     * Theme-->SubThemeVO
     */
    @Mappings(
            value = {
                    @Mapping(source = "themeId", target = "subThemeId"),
                    @Mapping(source = "themeTitle", target = "subThemeTitle"),
                    @Mapping(target = "completionStatus", ignore = true)
            }
    )
    SubThemeVO themeToSubThemeVO(Theme theme);

    //调用完自动转化后，会自动调用本方法
    @AfterMapping
    default void setCompletionStatus(Theme theme, @MappingTarget SubThemeVO subTheme){
        Integer completionStatus = theme.getCompletionStatus();
        ThemeCompletionStatus themeCompletionStatus = ThemeCompletionStatus.fromValue(completionStatus);
        subTheme.setCompletionStatus(new ThemeCompletionVO(themeCompletionStatus.getTitle(), themeCompletionStatus.getColor()));
    }


    List<SubThemeVO> themesToSubThemeVOs(List<Theme> themes);
}
